package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.enums.activity.eActivityCookBoyType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.rank.UnionActivityRank;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.logic.cross.CrossActivityUnionRankListModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.activity.relation.CrossRelationRankMgr;

/**
 * @author ：zfr
 * @date ：2021/8/16 15:03
 */
public class CookingBoyActivityRank extends BaseCrossRank {
    private int childType;

    public CookingBoyActivityRank(int activityId, int childType) {
        super(activityId);
        this.childType = childType;
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        int conditionType = 0;
        if (childType == eActivityCookBoyType.Process1.getChildType()) {
            conditionType = eGamePlayerEventType.CookBoy1IntegralUserCrossRank.getValue();
        } else if (childType == eActivityCookBoyType.Process2.getChildType()) {
            conditionType = eGamePlayerEventType.CookBoy2IntegralUserCrossRank.getValue();
        } else if (childType == eActivityCookBoyType.Process3.getChildType()) {
            conditionType = eGamePlayerEventType.CookBoy3IntegralUserCrossRank.getValue();
        }
        CrossActivityRankListModel rankListModel = CrossRelationRankMgr.getCrossActivityRankListModel(activityId);
        if (rankListModel != null) {
            int rank = 0;
            for (CrossUserRank rankData : rankListModel.getRankList()) {
                long userId = rankData.getUserId();
                rank++;
                addUserRankData(msg, conditionType, userId, rank);
            }
        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        int conditionType = 0;
        if (childType == eActivityCookBoyType.Process1.getChildType()) {
            conditionType = eGamePlayerEventType.CookBoy1IntegralUnionCrossRank.getValue();
        }
        CrossActivityUnionRankListModel rankListModel = CrossRelationRankMgr.getCrossActivityUnionRankListModel(activityId);
        int rank = 0;
        if (conditionType != 0) {
            if (rankListModel != null) {
                for (UnionActivityRank rankData : rankListModel.getRankList()) {
                    String unionUid = rankData.getUnionUid();
                    rank++;
                    addUnionRankData(msg, conditionType, unionUid, rank);
                }
            }
        }
        return msg;
    }
}
